<#import "../template.ftl" as t/>
<@t.html ; part>
    <#if part="head">
        <link href="<@spring.url "/resources/plugins/bootstrap-select/bootstrap-select.min.css"/>" rel="stylesheet">
    </#if>
    <#if part="body">
        <div class="row">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title">企业详细用电信息</h3>
                </div>
                <div class="panel-body">
                    <div class="panel-heading">
                        <h3 class="panel-title">供电信息</h3>
                    </div>
                        <form class="panel-body form-horizontal form-padding">
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="demo-text-input">电压等级（千伏）</label>
                                <div class="col-md-9">
                                    <select data-placeholder="请选择电压等级" class="selectpicker" id="voltageStep" tabindex="2">
                                        <option value="0.4" <#if ((detailInfo.voltageStep)?? && detailInfo.voltageStep=="0.4") || ((companyBak.voltageStep)?? && companyBak.voltageStep=="0.4")>selected="selected"</#if> >0.4</option>
                                        <option value="0.6" <#if ((detailInfo.voltageStep)?? && detailInfo.voltageStep=="0.6") || ((companyBak.voltageStep)?? && companyBak.voltageStep=="0.6")>selected="selected"</#if> >0.6</option>
                                        <option value="10" <#if ((detailInfo.voltageStep)?? && detailInfo.voltageStep=="10") || ((companyBak.voltageStep)?? && companyBak.voltageStep=="10")>selected="selected"</#if> >10</option>
                                        <option value="20" <#if ((detailInfo.voltageStep)?? && detailInfo.voltageStep=="20") || ((companyBak.voltageStep)?? && companyBak.voltageStep=="20")>selected="selected"</#if> >20</option>
                                        <option value="35" <#if ((detailInfo.voltageStep)?? && detailInfo.voltageStep=="35") || ((companyBak.voltageStep)?? && companyBak.voltageStep=="35")>selected="selected"</#if> >35</option>
                                        <option value="110" <#if ((detailInfo.voltageStep)?? && detailInfo.voltageStep=="110") || ((companyBak.voltageStep)?? && companyBak.voltageStep=="110")>selected="selected"</#if> >110</option>
                                        <option value="220" <#if ((detailInfo.voltageStep)?? && detailInfo.voltageStep=="220") || ((companyBak.voltageStep)?? && companyBak.voltageStep=="220")>selected="selected"</#if> >220</option>
                                    </select>
                                    <span> （千伏）</span>
                                    <small class="help-block" id="voltageStep_err" style="display: none">请选择电压等级</small>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="demo-email-input">户号个数</label>
                                <div class="col-md-4">
                                    <#if (detailInfo.elecAccountNum)??>
                                        <#assign accounts = detailInfo.elecAccountNum?split(",") >
                                        <input type="text" id="accountNum" name="accountNum" value="${(accounts?size)!(0)}" class="form-control" placeholder="">
                                    <#elseif (companyBak.elecAccountNum)??>
                                        <input type="text" id="accountNum" name="accountNum" value="${companyBak.elecAccountNum}" class="form-control" placeholder="">
                                    <#else>
                                        <input type="text" id="accountNum" name="accountNum" class="form-control" placeholder="">
                                    </#if>
                                    <small class="help-block"  id="accountNum_error" style="display: none">请输入户号个数，且为数字类型</small>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="demo-email-input">用电户号</label>
                                <div id="more_input" class="col-md-9">
                                    <#if (detailInfo.elecAccountNum)??>
                                        <#list detailInfo.elecAccountNum?split(",") as account>
                                        <div class="col-md-3">
                                            <input type="text" id="elecAccount" name="elecAccount" value="${account!}" class="form-control" placeholder="">
                                        </div>
                                        </#list>
                                    <#else>
                                        <div class="col-md-3">
                                            <input type="text" id="elecAccount" name="elecAccount" class="form-control" placeholder="">
                                        </div>
                                    </#if>
                                    <small class="help-block" id="elecAccount_error"  style="display: none">请输入用电户号，用电户号由数字组成</small>
                                </div>
                            </div>
                            <div class=" form-group row">
                                <label class="col-md-3 control-label" for="demo-email-input">用户容量总计</label>
                                <div class="col-md-4 input-group mar-btm">
                                    <input type="text" class="form-control" id="transformerCapacity" name="transformerCapacity" value="${(detailInfo.transformerCapacity)!}" class="form-control" placeholder="">
                                    <span class="input-group-addon">KVA(千伏安)</span>
                                </div>
                            </div>
                            <div class="form-group" id="transformerCapacity_err" style="display: none">
                                <label class="col-md-3 control-label" for="demo-email-input"></label>
                                <div class="col-md-6">
                                    <small class="help-block">请输入用户容量总计，并请输入数字类型</small>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-md-3 control-label" for="demo-email-input">用户预估电量（年）</label>
                                <div class="col-md-4 input-group mar-btm">
                                    <input type="text" id="elecConsumption" name="elecConsumption" value="<#if (detailInfo.elecConsumption)??>${(detailInfo.elecConsumption)!}<#else>${(companyBak.elecConsumption)!}</#if>" class="form-control" placeholder="">
                                    <span class="input-group-addon">万kW·h(万度)/年</span>
                                </div>
                            </div>
                            <div class="form-group"  id="elecConsumption_err" style="display: none">
                                <label class="col-md-3 control-label" for="demo-email-input"></label>
                                <div class="col-md-6">
                                    <small class="help-block">请输入用户预估电量，并请输入数字类型</small>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="demo-email-input">购电结算单位</label>
                                <div class="col-md-9">
                                    <small class="help-block" id="powerSupply_err">
                                        <#if (city.powerSupply)??>${city.powerSupply}</#if>
                                    </small>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="demo-email-input">供电区域</label>
                                <div class="col-md-9">
                                    <small class="help-block" id="address_err">江苏</small>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="demo-email-input">所属地级市</label>
                                <div class="col-md-9">
                                    <select data-placeholder="请选择地级市" class="selectpicker" id="cityId" tabindex="2">
                                        <#if cityList??>
                                            <#list cityList as c>
                                                <option value="${c.id}" <#if city?? && c.id==city.id>selected="selected"</#if> >${c.name}</option>
                                            </#list>
                                        </#if>
                                    </select>
                                    <small class="help-block" id="cityId_err" style="display: none">请选择所属地级市</small>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="demo-email-input">行业类别</label>
                                <div class="col-md-9">
                                    <select data-placeholder="请选择行业列表" class="selectpicker" id="detailCategory" name="detailCategory" tabindex="2">
                                        <option value="工业" <#if ((detailInfo.detailCategory)?? && detailInfo.detailCategory=="工业")>selected="selected"</#if> >工业</option>
                                        <option value="商业、住宿和餐饮业" <#if ((detailInfo.detailCategory)?? && detailInfo.detailCategory=="商业、住宿和餐饮业")>selected="selected"</#if> >商业、住宿和餐饮业</option>
                                        <option value="建筑业" <#if ((detailInfo.detailCategory)?? && detailInfo.detailCategory=="建筑业")>selected="selected"</#if> >建筑业</option>
                                        <option value="交通运输、仓储和邮政业" <#if ((detailInfo.detailCategory)?? && detailInfo.detailCategory=="交通运输、仓储和邮政业")>selected="selected"</#if> >交通运输、仓储和邮政业</option>
                                        <option value="信息传输、计算机和软件业" <#if ((detailInfo.detailCategory)?? && detailInfo.detailCategory=="信息传输、计算机和软件业")>selected="selected"</#if> >信息传输、计算机和软件业</option>
                                        <option value="金融、房地产、商务及居民服务业" <#if ((detailInfo.detailCategory)?? && detailInfo.detailCategory=="金融、房地产、商务及居民服务业")>selected="selected"</#if> >金融、房地产、商务及居民服务业</option>
                                        <option value="公共事业及管理组织" <#if ((detailInfo.detailCategory)?? && detailInfo.detailCategory=="公共事业及管理组织")>selected="selected"</#if> >公共事业及管理组织</option>
                                        <option value="农、林、牧、渔业" <#if ((detailInfo.detailCategory)?? && detailInfo.detailCategory=="农、林、牧、渔业")>selected="selected"</#if> >农、林、牧、渔业</option>
                                    </select>
                                    <small class="help-block" id="detailCategory_err" style="display: none">请输入行业类别</small>
                                </div>
                            </div>
                            <div class="panel-heading">
                                <h3 class="panel-title">商务信息</h3>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="demo-email-input">开户银行</label>
                                <div class="col-md-6">
                                    <input type="text" id="bankName" name="bankName" value="${(detailInfo.bankName)!}" class="form-control" placeholder="">
                                    <small class="help-block" id="bankName_err" style="display: none">请输入开户银行</small>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="demo-email-input">开户名称</label>
                                <div class="col-md-6">
                                    <input type="text" id="bankAccountName" name="bankAccountName" value="${(detailInfo.bankAccountName)!}" class="form-control" placeholder="">
                                    <small class="help-block" id="bankAccountName_err" style="display: none">请输入开户名称</small>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="demo-email-input">开户账号</label>
                                <div class="col-md-6">
                                    <input type="text" id="bankAccount" name="bankAccount" value="${(detailInfo.bankAccount)!}" class="form-control" placeholder="">
                                    <small class="help-block" id="bankAccount_err" style="display: none">请输入开户账号，请填入16~19位的数字</small>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-md-3 control-label" for="demo-email-input">办公电话</label>
                                <div class="col-md-6 input-group mar-btm">
                                    <input type="text" id="contactPhone" name="contactPhone" value="${(detailInfo.contactPhone)!}" class="form-control" placeholder="">
                                    <span class="input-group-addon">例："0512-67676767"</span>
                                </div>
                            </div>
                            <div class="form-group"  id="contactPhone_err" style="display: none">
                                <label class="col-md-3 control-label" for="demo-email-input"></label>
                                <div class="col-md-6">
                                    <small class="help-block">请输入办公电话，形如"0512-67676767"</small>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="demo-email-input">传真号码</label>
                                <div class="col-md-6">
                                    <input type="text" id="fax" name="fax" value="${(detailInfo.fax)!}" class="form-control" placeholder="">
                                    <small class="help-block" id="fax_err" style="display: none">请输入传真号码</small>
                                </div>
                            </div>
                            <div class="panel-footer text-right">
                                <button class="btn btn-success" type="button" onclick="save_info()">提交</button>
                            </div>
                            <input type="hidden" id="currentId" name="currentId" value="${(detailInfo.id)!}" />
                            <input type="hidden" id="companyId" name="companyId" value="${(companyInfo.id)!}" />
                            <input type="hidden" id="fromU" name="fromU" value="${from!(0)}" />
                        </form>
                </div>
            </div>
        </div>
    </#if>
    <#if part="modal">
    </#if>

    <#if part="foot_script">
    <script src="<@spring.url "/resources/plugins/bootstrap-select/bootstrap-select.min.js"/>"></script>
    <script type="text/javascript">
        $("#accountNum").bind("input propertychange",function(event){
            var accountNum = $("#accountNum").val();
            var divNum = $("#more_input").find(".col-md-3");
            if ($.trim(accountNum) != "" && !isNaN($.trim(accountNum))) {
                $("#accountNum_error").hide();
                if (divNum.length < parseFloat(accountNum)) {
                    for (var i=0; i<accountNum-divNum.length; i++) {
                        $("#more_input").append("<div class=\"col-md-3\">\n" +
                                "<input type=\"text\" id=\"elecAccount\" name=\"elecAccount\" class=\"form-control\" placeholder=\"\">\n" +
                                "</div>");
                    }
                } else if (divNum.length > parseFloat(accountNum)) {
                    for (var i=divNum.length-1; i>accountNum-1; i--) {
                        $(divNum[i]).remove();
                    }
                }
            } else {
                $("#accountNum_error").show();
            }
        });

        function save_info() {
            $("#voltageStep_err").hide();
            $("#elecAccount_error").hide();
            $("#transformerCapacity_err").hide();
            $("#elecConsumption_err").hide();
            $("#cityId_err").hide();
            $("#detailCategory_err").hide();
            $("#bankName_err").hide();
            $("#bankAccountName_err").hide();
            $("#bankAccount_err").hide();
            $("#contactPhone_err").hide();
            $("#fax_err").hide();
            var voltageStep = $.trim($("#voltageStep").val());
            if (voltageStep == "") {
                $("#voltageStep_err").show();
                return false;
            }
            var accounts = $("input[name='elecAccount']");
            var accountArr = "";
            var isNotNum = true;
            if (accounts != null && accounts.length>0) {
                for (var i=0; i<accounts.length; i++) {
                    if ($.trim($(accounts[i]).val()) != "") {
                        if (accountArr != "") {
                            accountArr += ",";
                        }
                        accountArr += $.trim($(accounts[i]).val());
                    }
                    if (isNaN($.trim($.trim($(accounts[i]).val())))) {
                        isNotNum = false;
                    }
                }
            }
            if (accountArr == "" || isNotNum==false) {
                $("#elecAccount_error").show();
                return false;
            }

            var transformerCapacity = $.trim($("#transformerCapacity").val());
            if (transformerCapacity == "" || isNaN(transformerCapacity)) {
                $("#transformerCapacity_err").show();
                return false;
            }
            var elecConsumption = $.trim($("#elecConsumption").val());
            if (elecConsumption == "" || isNaN(elecConsumption)) {
                $("#elecConsumption_err").show();
                return false;
            }
            var cityId = $.trim($("#cityId").val());
            if (cityId == "") {
                $("#cityId_err").show();
                return false;
            }
            var detailCategory = $.trim($("#detailCategory").val());
            if (detailCategory == "") {
                $("#detailCategory_err").show();
                return false;
            }
            var bankName = $.trim($("#bankName").val());
            if (bankName == "") {
                $("#bankName_err").show();
                return false;
            }
            var bankAccountName = $.trim($("#bankAccountName").val());
            if (bankAccountName == "") {
                $("#bankAccountName_err").show();
                return false;
            }
            var bankAccount = $.trim($("#bankAccount").val());
            if (bankAccount == "" || isNaN(bankAccount) || bankAccount.length>19 || bankAccount.length<16) {
                $("#bankAccount_err").show();
                return false;
            }
            var contactPhone = $.trim($("#contactPhone").val());
            if (contactPhone == "") {
                $("#contactPhone_err").show();
                return false;
            }
            var reg=/^((0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
            if(!reg.test(contactPhone)) {
                $("#contactPhone_err").show();
                return false;
            }

            var fax = $.trim($("#fax").val());
            if (fax == "") {
                $("#wfax_err").show();
                return false;
            }
            var currentId = $("#currentId").val();
            var companyId = $("#companyId").val();
            var fromU = $("#fromU").val();
            $.post("<@spring.url "/companyInfo/detailUpdate"/>",{
                id:currentId, companyId:companyId, voltageStep:voltageStep, accountArr:accountArr,
                transformerCapacity:transformerCapacity, elecConsumption:elecConsumption,
                cityId:cityId, detailCategory:detailCategory, bankName:bankName, bankAccountName:bankAccountName,
                bankAccount:bankAccount, contactPhone:contactPhone, fax:fax
            }, function (data) {
                if (data.code == 1) {
                    alert("企业详细信息编辑成功。");
                    if (fromU != "" && fromU == 1){
                        window.location.href="<@spring.url "/contractInfo/show/"/>"+data.result.companyInfoId+"/pro";
                    } else {
                        window.location.href="<@spring.url "/companyInfo/editDetail/"/>"+data.result.id;
                    }
                } else {
                    alert(data.message);
                }

            });
        }
    </script>
    </#if>
</@t.html>